home *** CD-ROM | disk | FTP | other *** search
- Path: li.net!jeremy
- From: jeremy@newshost.li.net (Jeremy Markman)
- Newsgroups: comp.lang.c
- Subject: Re: Help: array of ptrs to structures
- Date: 4 Apr 1996 14:18:43 GMT
- Organization: LI Net (Long Island Network)
- Message-ID: <4k0lo3$hn6@linet06.li.net>
- References: <Pine.SOL.3.91-941213.960403155531.22205C-100000@altair.dur.ac.uk>
- NNTP-Posting-Host: linet04.li.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Ed Wiles (E.D.Wiles@durham.ac.uk) wrote:
- : 1) How do I hard-code, for example, the third person in the array to be:
- : lastname = "Adcock"; firstname = "Lucy"; phone = "(01623) 943086"; ?
-
- : *phone_book[2] = {"Adcock", "Lucy", etc.} is not allowed, so do I have to
- : assign each structure member individually?
- : i.e. *phone_book[2]->lastname = "Adcock", etc.
-
- strcpy(phone_book[2]->lastname,"Adcock");
- but make sure you use malloc() to allocate memory
- i.e. phone_book[2] = malloc(sizeof(struct person));
- etc...
-
- : go: is there a way of doing this when I declare the variable phone_book,
- : remembering that e.g. int odds[] = {1, 3, 5, 7} is allowed?)
-
- yes, that is allowed!
-
- : 2) I want to pass the entire array to a function. Do I just pass it as
- : phone_book? Should the function's corresponding formal parameter be
- : struct person *anyname[] ?
- Yes, also using struct person **anyname is acceptable...
-
-